import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath } from "node:url";
import replace from "@rollup/plugin-replace";


// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  // console.log(mode)
  // console.log(123456)
  const base = mode === 'development' ? './' : '/admin/'
  // const base = './'
  //  打包时候变化
  console.log(process.env.npm_lifecycle_event)

  // console.log(import.meta?.env.VITE_BASE_URL)
  // mode === 'development'
  return {
    plugins: [
      vue(),
      replace({
        preventAssignment: true, // 防止全局变量污染
        "document.cookie": "''" // 将 document.cookie 替换为空字符串
      })
    ],
    define: {
      'process.env': {
        run: process.env.npm_lifecycle_event
      }
    },
    base,
    resolve: {
      // 设置别名
      alias: {
        "@": fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    // 设置前端开发环境服务访问
    server: {
      port: 9000,
      open: false,
      host: '0.0.0.0',
    },
  }
})
